package logic

import (
	"context"
	"work/workrpc/workrpc"

	"work/api/internal/svc"
	"work/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type StoryAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewStoryAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StoryAddLogic {
	return &StoryAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *StoryAddLogic) StoryAdd(req *types.StoryAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.WorkRpc.StoryAdd(l.ctx, &workrpc.StoryAddRequest{
		Title: req.Title,
		Typer: req.Typer,
		Label: req.Label,
		Brief: req.Brief,
	})
	if err != nil {
		return &types.Response{
			Message: "小说添加失败",
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "小说添加成功",
		Code:    200,
		Data:    add,
	}, nil
}
